package cn.jinjimi.app.main.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import cn.jinjimi.base.util.SharePlatForm;
import cn.jinjimi.app.R;
import cn.jinjimi.app.main.adapter.extend.MyBaseAdapter;

/**
 * Created by Roy
 * Date: 16/1/8
 */
public class SharePlatFormAdapter extends MyBaseAdapter<SharePlatForm> {
    private Context mContext;

    public SharePlatFormAdapter(Context context) {
        this.mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;

        if (convertView == null) {
            convertView = View.inflate(mContext, R.layout.share_platform_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        SharePlatForm item = getItem(position);

        if (item == null)
            return convertView;

        switch (item.ordinal()) {
            case SharePlatForm.WEIXIN_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_weixin);
                holder.tvTitle.setText(R.string.share_wechat);
                break;
            case SharePlatForm.WEIXIN_CIRCLE_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_pengyouquan);
                holder.tvTitle.setText(R.string.share_wechat_friend);
                break;
            case SharePlatForm.QQ_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_qq);
                holder.tvTitle.setText(R.string.share_qq);
                break;
            case SharePlatForm.QZONE_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_qzone);
                holder.tvTitle.setText(R.string.share_qq_zone);
                break;
            case SharePlatForm.SMS_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_sms);
                holder.tvTitle.setText(R.string.share_sms);
                break;
            case SharePlatForm.COPYLINK_INDEX:
                holder.img.setImageResource(R.drawable.share_icon_copylink);
                holder.tvTitle.setText(R.string.share_copylink);
                break;
        }

        return convertView;
    }

    class ViewHolder {

        public ImageView img;
        public TextView tvTitle;

        public ViewHolder(View itemView) {
            img = (ImageView) itemView.findViewById(R.id.img);
            tvTitle = (TextView) itemView.findViewById(R.id.tv_title);
        }
    }
}
